<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="物料入库单号" prop="recptCode">
        <el-input v-model="queryParams.recptCode" placeholder="请输入物料入库单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="收货单据编号" prop="poCode">
        <el-input v-model="queryParams.poCode" placeholder="请输入收货单据编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- 2024-12-5 djj 搜索条件增加入库类型 begin -->
      <el-form-item label="入库类型" prop="attr3">
        <el-select v-model="queryParams.attr3" placeholder="请选择入库类型" clearable>
          <el-option v-for="dict in dict.type.mes_item_recpt_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- 2024-12-5 djj 搜索条件增加入库类型 end -->

      <!-- <el-form-item label="供应商名称" prop="vendorName">
        <el-input
          v-model="queryParams.vendorName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <!-- <el-form-item label="是否直发" prop="isDirectItem">
        <el-select v-model="queryParams.isDirectItem" clearable >
          <el-option label="否" value="0"></el-option>
          <el-option label="是" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入库日期" prop="recptDate">
        <el-date-picker clearable
          v-model="queryParams.recptDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择入库日期">
        </el-date-picker>
      </el-form-item>-->

      <el-form-item label="创建日期">
        <el-date-picker v-model="queryParams.time" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>
      <el-form-item label="入库日期">
        <el-date-picker v-model="queryParams.time2" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:wm:itemrecpt:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:wm:itemrecpt:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" icon="el-icon-share" @click="handleSerial">打印序列号</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" icon="el-icon-share" @click="batchNumber">打印批次号</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" icon="el-icon-share" @click="inboundBatchesPrint">入库批次打印</el-button>
      </el-col>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="itemrecptList" @selection-change="handleSelectionChange" height="calc(100vh - 260px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="50px" prop="issueCode">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="物料入库单号" align="center" prop="recptCode">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">{{
            scope.row.recptCode }}</el-button>
        </template>
      </el-table-column>

      <!--      <el-table-column label="入库单名称" align="center" prop="recptName" />-->
      <!--      <el-table-column label="来料检验单ID" align="center" prop="iqcId" />-->
      <el-table-column label="来料检验单编号" align="center" prop="iqcCode" />
      <el-table-column label="收货单据编号" align="center" prop="poCode" />
      <!-- 2024-12-5 djj 增加入库类型 begin -->
      <el-table-column label="入库类型" align="center" prop="billTypeName" />
      <!-- 2024-12-5 djj 增加入库类型 end -->
      <!--      <el-table-column label="供应商编码" align="center" prop="vendorCode" />-->
      <!--      <el-table-column label="供应商名称" align="center" prop="vendorName" />-->
      <!--      <el-table-column label="供应商简称" align="center" prop="vendorNick" />-->
      <!-- <el-table-column label="仓库ID" align="center" prop="warehouseId" /> -->
      <!-- <el-table-column label="仓库编码" align="center" prop="warehouseCode" /> -->
      <!-- <el-table-column label="仓库名称" align="center" prop="warehouseName" /> -->
      <!--      <el-table-column label="库区ID" align="center" prop="locationId" />-->
      <!--      <el-table-column label="库区编码" align="center" prop="locationCode" />-->
      <!--      <el-table-column label="库区名称" align="center" prop="locationName" />-->
      <!--      <el-table-column label="库位ID" align="center" prop="areaId" />-->
      <!--      <el-table-column label="库位编码" align="center" prop="areaCode" />-->
      <!--      <el-table-column label="库位名称" align="center" prop="areaName" />-->
      <!--      <el-table-column label="入库日期" align="center" prop="recptDate" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.recptDate, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!-- <el-table-column label="单据编号" align="center" prop="fbillNo" /> -->
      <!-- <el-table-column label="单据类型" align="center" prop="fbillTypeID" /> -->
      <el-table-column label="质检人" align="center" prop="createBy" />
      <el-table-column label="创建日期" align="center" prop="createTime" />
      <el-table-column label="入库人" align="center" prop="attr1" />
      <el-table-column label="入库日期" align="center" prop="recptDate" />
      <!-- <el-table-column label="入库人" align="center" prop="createBy" /> -->
      <!-- <el-table-column label="收料组织" align="center" prop="fstockOrgId" /> -->
      <!-- <el-table-column label="采购组织" align="center" prop="fpurchaseOrgId" /> -->
      <!-- <el-table-column label="供应商" align="center" prop="fsupplierId" /> -->
      <!-- <el-table-column label="货主类型" align="center" prop="fownerTypeIdHead" /> -->
      <!-- <el-table-column label="货主" align="center" prop="fownerIdHead" /> -->
      <!-- <el-table-column label="物料编码" align="center" prop="fmaterialId" />
      <el-table-column label="物料说明" align="center" prop="fmaterialDesc" />-->
      <!-- <el-table-column label="是否直发" align="center" prop="isDirectItem" >
        <template slot-scope="scope">
          <el-switch
          v-model="scope.row.isDirectItem"
          active-value="1"
          inactive-value="0"
          disabled
          ></el-switch>
        </template>
      </el-table-column>-->
      <!-- <el-table-column label="库存单位" align="center" prop="fstockUnitID" /> -->
      <!-- <el-table-column label="计价单位" align="center" prop="fpriceUnitId" /> -->
      <!-- <el-table-column label="货主类型1" align="center" prop="fownertypeid" /> -->
      <!--      <el-table-column label="采购单位" align="center" prop="fremainInStockUnitId" />-->
      <!-- <el-table-column label="货主1" align="center" prop="fownerid" /> -->
      <el-table-column label="单据状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_order_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-share" @click="handlePrint(scope.row)">打印序列号条码</el-button>
          <el-button size="mini" type="text" icon="el-icon-share" @click="handleBatch(scope.row)">打印批次号条码</el-button>
          <el-button size="mini" type="text" icon="el-icon-share" v-if="scope.row.status == 'PREPARE'" @click="handleExecute(scope.row)" v-hasPermi="['mes:wm:itemrecpt:exec']">执行入库</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status =='PREPARE'"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes:wm:itemrecpt:edit']"
          >修改</el-button>-->
          <el-button size="mini" type="text" icon="el-icon-printer" @click="giveDataInfo(scope.row)" v-if="scope.row.status != 'PREPARE'" v-hasPermi="['mes:wm:itemrecpt:print']">打印入库单</el-button>
          <el-button size="mini" type="text" icon="el-icon-refrigerator" @click="handleFreeze(scope.row)" v-if="scope.row.freeze === 1" v-hasPermi="['mes:wm:itemrecpt:freeze']">冻结</el-button>
          <el-button size="mini" type="text" icon="el-icon-refrigerator" @click="saveToErp(scope.row)" v-if="scope.row.toErpStatus === 0&&scope.row.status=='FINISHED'" v-hasPermi="['mes:k3cloud:wmItemRecpt:saveToErp']">上传ERP</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-if="scope.row.status =='PREPARE'"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes:wm:itemrecpt:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改物料入库单对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="入库单编号" prop="recptCode">
              <el-input v-model="form.recptCode" placeholder="请输入入库单编号" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label-width="80">
              <el-switch
                v-model="autoGenFlag"
                active-color="#13ce66"
                active-text="自动生成"
                @change="handleAutoGenChange(autoGenFlag)"
                v-if="optType != 'view' && form.status =='PREPARE'"
              ></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入库单名称" prop="recptName">
              <el-input v-model="form.recptName" placeholder="请输入入库单名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="入库日期" prop="recptDate">
              <el-date-picker
                clearable
                v-model="form.recptDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择入库日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="采购订单号" prop="poCode">
              <el-input v-model="form.poCode" placeholder="请输入采购订单号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单据状态" prop="status">
              <el-select v-model="form.status" disabled placeholder="请选择单据状态">
                <el-option
                  v-for="dict in dict.type.mes_order_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="来料检验单" prop="iqcCode">
              <el-input v-model="form.iqcCode" readonly="readonly" placeholder="请选择来料检验单">
                <el-button slot="append" @click="handleSelectIqc" icon="el-icon-search"></el-button>
              </el-input>
              <IqcSelect ref="iqcSelect" @onSelected="onIqcSelected"></IqcSelect>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="供应商" prop="vendorName">
              <el-input v-model="form.vendorName" readonly="readonly" placeholder="请选择供应商">
                <el-button slot="append" @click="handleSelectVendor" icon="el-icon-search"></el-button>
              </el-input>
              <VendorSelect ref="vendorSelect" @onSelected="onVendorSelected" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入库仓库">
              <el-cascader
                v-model="warehouseInfo"
                :options="warehouseOptions"
                :props="warehouseProps"
                @change="handleWarehouseChanged"
              ></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="是否直发">
              <el-select v-model="form.isDirectItem" value="0">
                <el-option label="否" value="0"></el-option>
                <el-option label="是" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-divider v-if="form.recptId !=null" content-position="center">物料信息</el-divider>
      <el-card shadow="always" v-if="form.recptId !=null" class="box-card">
        <Itemrecptline
          ref="line"
          :recptId="form.recptId"
          :warehouseId="form.warehouseId"
          :locationId="form.locationId"
          :areaId="form.areaId"
          :optType="optType"
        ></Itemrecptline>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="cancel"
          v-if="optType =='view' || form.status !='PREPARE' "
        >返回</el-button>
        <el-button
          type="primary"
          @click="submitForm"
          v-if="form.status =='PREPARE' && optType !='view' "
        >保 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
    <ItemrecptPrint v-if="opensorting" ref="itemrecptPrint"></ItemrecptPrint>
    <Detail v-if="open" ref="detailDialog"></Detail>
  </div>
</template>

<script>
import {
  listItemrecpt,
  getItemrecpt,
  delItemrecpt,
  addItemrecpt,
  updateItemrecpt,
  confirmItemrecpt,
  execute,
  printItem,
  batchItem,
  batchItem2,
  getItemRecptItems,
  getItemsRecpt,
  wmItemRecptItemListBantch,
  wmItemRecptItemListBantch2,
  editFreeze,
  saveToErp
} from "@/api/mes/wm/itemrecpt";
import { getTreeList } from "@/api/mes/wm/warehouse";
import { genCode } from "@/api/mes/md/rule";
import VendorSelect from "@/components/vendorSelect/single.vue";
import IqcSelect from "@/components/iqcSelect/single.vue";
import Itemrecptline from "./line.vue";
import Detail from "./itemDetails.vue";
import ItemrecptPrint from "./print/itemrecptPrint";
export default {
  name: "Itemrecpt",
  dicts: ["mes_order_status", "mes_item_recpt_type"],
  components: {
    VendorSelect,
    IqcSelect,
    Itemrecptline,
    ItemrecptPrint,
    Detail,
  },
  data() {
    return {
      //自动生成编码
      autoGenFlag: false,
      optType: undefined,
      warehouseInfo: [],
      warehouseOptions: [],
      warehouseProps: {
        multiple: false,
        value: "pId",
        label: "pName",
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      recptCodes: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料入库单表格数据
      itemrecptList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      opensorting: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        recptCode: null,
        recptName: null,
        iqcId: null,
        iqcCode: null,
        vendorId: null,
        vendorCode: null,
        vendorName: null,
        vendorNick: null,
        warehouseId: null,
        warehouseCode: null,
        warehouseName: null,
        locationId: null,
        locationCode: null,
        locationName: null,
        areaId: null,
        areaCode: null,
        areaName: null,
        recptDate: null,
        poCode: null,
        isDirectItem: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        recptCode: [
          { required: true, message: "物料入库单号不能为空", trigger: "blur" },
        ],
        recptName: [
          { required: true, message: "入库单名称不能为空", trigger: "blur" },
        ],
        recptDate: [
          { required: true, message: "入库时间不能为空", trigger: "blur" },
        ],
        vendorName: [
          { required: true, message: "请选择对应的供应商", trigger: "blur" },
        ],
      },
      //打印需要的数组
      wmItemRecptItemList: [],
    };
  },
  created() {
    this.getList();
    this.getWarehouseList();
  },
  methods: {
    saveToErp(data) {
      saveToErp(data.recptId).then(msg => {
        if (msg.code == 200) {
          this.getList()
          this.loading = false
          this.$message.success("操作成功！");
        } else {
          this.loading = false
        }
      })
    },
    handleFreeze(row) {
      const that = this;
      this.$modal
        .confirm("是否确认冻结物料入库单？")
        .then(function () {
          const params = {
            recptId: row.recptId,
            freeze: 0,
          };
          editFreeze(params).then((res) => {
            that.$modal.msgSuccess("冻结成功");
            that.getList();
          });
        })
        // .then(() => {
        //   this.$modal.msgSuccess("冻结成功");
        // })
        .catch((err) => {
          console.log(111, err);
        });
    },
    giveDataInfo(row) {
      this.opensorting = true;
      this.$nextTick(() => {
        // 2024-12-5 djj 更改为动态标题 begin
        if (row.attr3 == 1) { this.$refs.itemrecptPrint.printContentTitle = '退料入库单' }
        else { this.$refs.itemrecptPrint.printContentTitle = '采购入库单' }
        // 2024-12-5 djj 更改为动态标题 end
        this.$refs.itemrecptPrint.init(row);
      });
      // issueInfoList(row.issueId).then(res => {
      //   if (res.code == 200) {
      //     this.ticketData1 = res.data;
      //     console.info('this.ticketData1',this.ticketData1)
      //     this.print1();
      //   }
      // });
    },
    /** 查询物料入库单列表 */
    getList() {
      this.loading = true;
      listItemrecpt(this.queryParams).then((response) => {
        this.itemrecptList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getWarehouseList() {
      getTreeList().then((response) => {
        if (response.data) {
          this.warehouseOptions = response.data.filter((el) => {
            return el.warehouseCode.indexOf("VIR") == -1;
          });
        }
        this.warehouseOptions.map((w) => {
          w.children.map((l) => {
            let lstr = JSON.stringify(l.children)
              .replace(/locationId/g, "lId")
              .replace(/areaId/g, "pId")
              .replace(/areaName/g, "pName");
            l.children = JSON.parse(lstr);
          });

          let wstr = JSON.stringify(w.children)
            .replace(/warehouseId/g, "wId")
            .replace(/locationId/g, "pId")
            .replace(/locationName/g, "pName");
          w.children = JSON.parse(wstr);
        });
        let ostr = JSON.stringify(this.warehouseOptions)
          .replace(/warehouseId/g, "pId")
          .replace(/warehouseName/g, "pName");
        this.warehouseOptions = JSON.parse(ostr);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recptId: null,
        recptCode: null,
        recptName: null,
        iqcId: null,
        iqcCode: null,
        vendorId: null,
        vendorCode: null,
        vendorName: null,
        vendorNick: null,
        warehouseId: null,
        warehouseCode: null,
        warehouseName: null,
        locationId: null,
        locationCode: null,
        locationName: null,
        areaId: null,
        areaCode: null,
        areaName: null,
        recptDate: null,
        poCode: null,
        status: "PREPARE",
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.autoGenFlag = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(this.queryParams, "=====queryParams===");
      if (this.queryParams.time) {
        this.queryParams["createTimeBegin"] = this.queryParams.time[0];
        this.queryParams["createTimeEnd"] = this.queryParams.time[1];
      } else {
        this.queryParams["createTimeBegin"] = null;
        this.queryParams["createTimeEnd"] = null;
      }

      if (this.queryParams.time2) {
        this.queryParams["recptDateBegin"] = this.queryParams.time2[0];
        this.queryParams["recptDateEnd"] = this.queryParams.time2[1];
      } else {
        this.queryParams["recptDateBegin"] = null;
        this.queryParams["recptDateEnd"] = null;
      }

      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.time = null;
      this.queryParams.time2 = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.recptId);
      this.recptCodes = selection.map((item) => item.recptCode);
      this.queryParams.wmItemRecptIdList = selection.map(
        (item) => item.recptId
      );
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.warehouseInfo = [];
      this.open = true;
      this.title = "添加物料入库单";
      this.optType = "add";
    },
    // 查询明细按钮操作
    handleView(row) {
      this.reset();
      this.open = true;
      console.log(row, "====row-====");
      this.$nextTick(() => {
        this.$refs.detailDialog.init(row);
      });
      // const recptIds = row.recptId;
      // getItemrecpt(recptIds).then(response => {
      //   debugger;
      //   this.form = response.data;
      //   this.warehouseInfo[0] = response.data.warehouseId;
      //   this.warehouseInfo[1] = response.data.locationId;
      //   this.warehouseInfo[2] = response.data.areaId;
      //   this.open = true;
      //   this.title = "查看入库单信息";
      //   this.optType = "view";
      // });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recptId = row.recptId || this.ids;
      getItemrecpt(recptId).then((response) => {
        this.form = response.data;
        this.warehouseInfo[0] = response.data.warehouseId;
        this.warehouseInfo[1] = response.data.locationId;
        this.warehouseInfo[2] = response.data.areaId;
        this.open = true;
        this.title = "修改物料入库单";
        this.optType = "edit";
      });
    },
    //打印前需要调的接口
    getItems(row) { },
    //批量 序列号打印
    handleSerial() {
      //判断是否勾选
      if (this.ids.length === 0) {
        this.$modal.msgWarning("请勾选需要打印的数据");
        return;
      }
      getItemsRecpt(this.ids).then((res) => {
        console.log(res, "打印前需要调的接口res");
        if (res.code === 200) {
          this.wmItemRecptItemList = res.data;
          this.$modal
            .confirm('是否确认打印物料编号为"' + this.ids + '"的数据项？')
            .then(() => {
              return printItem(this.wmItemRecptItemList);
            })
            .then(() => {
              this.getList();
              this.$modal.msgSuccess("打印成功");
            })
            .catch(() => {
              // 处理异常情况
              console.error("打印出错");
            });
        } else {
          // 处理接口返回的错误信息
          console.error("接口调用失败:", response.message);
        }
      });
    },
    //批量打印批次号
    batchNumber() {
      //判断是否勾选
      if (this.ids.length === 0) {
        this.$modal.msgWarning("请勾选需要打印的数据");
        return;
      }
      console.log(this.ids, "=========ids======");
      wmItemRecptItemListBantch(this.ids)
        .then((response) => {
          if (response.code === 200) {
            this.wmItemRecptItemList = response.data;
            this.$modal
              .confirm(
                '是否确认打印物料入库单号为"' + this.recptCodes + '"的数据项？'
              )
              .then(() => {
                return batchItem(this.wmItemRecptItemList);
              })
              .then(() => {
                this.getList();
                this.$modal.msgSuccess("打印成功");
              })
              .catch(() => {
                // 处理异常情况
                console.error("打印出错");
              });
          } else {
            // 处理接口返回的错误信息
            console.error("接口调用失败:", response.message);
          }
        })
        .catch((error) => {
          // 处理异常情况
          console.error("接口调用异常:", error);
        });
    },
    inboundBatchesPrint() {
      //判断是否勾选
      if (this.ids.length === 0) {
        this.$modal.msgWarning("请勾选需要打印的数据");
        return;
      }
      console.log(this.ids, "=========ids======");
      wmItemRecptItemListBantch2(this.ids)
        .then((response) => {
          if (response.code === 200) {
            let query = response.data;
            this.$modal
              .confirm(
                '是否确认打印物料入库单号为"' + this.recptCodes + '"的数据项？'
              )
              .then(() => {
                return batchItem2(query);
              })
              .then(() => {
                this.getList();
                this.$modal.msgSuccess("打印成功");
              })
              .catch(() => {
                // 处理异常情况
                console.error("打印出错");
              });
          } else {
            // 处理接口返回的错误信息
            console.error("接口调用失败:", response.message);
          }
        })
        .catch((error) => {
          // 处理异常情况
          console.error("接口调用异常:", error);
        });
    },
    //打印序列号条码
    handlePrint(row) {
      console.log(row, "打印序列号条码的row");
      getItemRecptItems(row.recptId)
        .then((response) => {
          console.log(response, "打印前需要调的接口res");
          if (response.code === 200) {
            this.wmItemRecptItemList = response.data;
            const recptCode = row.recptCode;
            this.$modal
              .confirm('是否确认打印物料编号为"' + recptCode + '"的数据项？')
              .then(() => {
                console.log(this.wmItemRecptItemList, "WmIssueLineList");
                return printItem(this.wmItemRecptItemList);
              })
              .then(() => {
                this.getList();
                this.$modal.msgSuccess("打印成功");
              })
              .catch(() => {
                // 处理异常情况
                console.error("打印出错");
              });
          } else {
            // 处理接口返回的错误信息
            console.error("接口调用失败:", response.message);
          }
        })
        .catch((error) => {
          // 处理异常情况
          console.error("接口调用异常:", error);
        });
    },
    //打印批次号条码
    handleBatch(row) {
      console.log(row, "打印批次号条码的row");
      let param = [];
      param.push(row.recptId);
      wmItemRecptItemListBantch(param)
        .then((response) => {
          console.log(response, "打印前需要调的接口res");
          if (response.code === 200) {
            this.wmItemRecptItemList = response.data;
            const recptCode = row.recptCode;
            this.$modal
              .confirm('是否确认打印物料编号为"' + recptCode + '"的数据项？')
              .then(() => {
                console.log(this.wmItemRecptItemList, "WmIssueLineList");
                return batchItem(this.wmItemRecptItemList);
              })
              .then(() => {
                this.getList();
                this.$modal.msgSuccess("打印成功");
              })
              .catch(() => {
                // 处理异常情况
                console.error("打印出错");
              });
          } else {
            // 处理接口返回的错误信息
            console.error("接口调用失败:", response.message);
          }
        })
        .catch((error) => {
          // 处理异常情况
          console.error("接口调用异常:", error);
        });
    },
    //执行入库
    handleExecute(row) {
      const recptIds = row.recptId || this.ids;
      this.$modal
        .confirm("确认执行入库？")
        .then(function () {
          return execute(recptIds); //执行入库
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("入库成功");
        })
        .catch(() => { });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.recptId != null) {
            updateItemrecpt(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addItemrecpt(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    doconfirm() {
      let that = this;
      this.$modal
        .confirm("是否完成入库单编制？【完成后将不能更改】")
        .then(function () {
          that.form.status = "CONFIRMED";
          that.submitForm();
        });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const recptIds = row.recptId || this.ids;
      this.$modal
        .confirm("是否确认删除物料入库单？")
        .then(function () {
          return delItemrecpt(recptIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      console.log(this.queryParams, "=====queryParams===");
      if (this.queryParams.time) {
        this.queryParams["createTimeBegin"] = this.queryParams.time[0];
        this.queryParams["createTimeEnd"] = this.queryParams.time[1];
      } else {
        this.queryParams["createTimeBegin"] = null;
        this.queryParams["createTimeEnd"] = null;
      }

      if (this.queryParams.time2) {
        this.queryParams["recptDateBegin"] = this.queryParams.time2[0];
        this.queryParams["recptDateEnd"] = this.queryParams.time2[1];
      } else {
        this.queryParams["recptDateBegin"] = null;
        this.queryParams["recptDateEnd"] = null;
      }

      this.download(
        "mes/wm/itemrecpt/export",
        {
          ...this.queryParams,
        },
        `itemrecpt_${new Date().getTime()}.xlsx`
      );
    },
    //选择默认的仓库、库区、库位
    handleWarehouseChanged(obj) {
      if (obj != null) {
        this.form.warehouseId = obj[0];
        this.form.locationId = obj[1];
        this.form.areaId = obj[2];
      }
    },
    //IQC检验单选择
    handleSelectIqc() {
      this.$refs.iqcSelect.showFlag = true;
    },
    //IQC检验单选择弹出框
    onIqcSelected(obj) {
      if (obj != undefined && obj != null) {
        this.form.iqcId = obj.iqcId;
        this.form.iqcCode = obj.iqcCode;
        this.form.recptName = obj.iqcName;
        this.form.vendorId = obj.vendorId;
        this.form.vendorCode = obj.vendorCode;
        this.form.vendorName = obj.vendorName;
        this.form.vendorNick = obj.vendorNick;
      }
    },
    //供应商选择
    handleSelectVendor() {
      this.$refs.vendorSelect.showFlag = true;
    },
    //供应商选择弹出框
    onVendorSelected(obj) {
      if (obj != undefined && obj != null) {
        this.form.vendorId = obj.vendorId;
        this.form.vendorCode = obj.vendorCode;
        this.form.vendorName = obj.vendorName;
        this.form.vendorNick = obj.vendorNick;
      }
    },
    //自动生成编码
    handleAutoGenChange(autoGenFlag) {
      if (autoGenFlag) {
        genCode("ITEMRECPT_CODE").then((response) => {
          this.form.recptCode = response;
        });
      } else {
        this.form.recptCode = null;
      }
    },
  },
};
</script>
<style scoped>
.collapse-title {
  flex: 0 1 54%;
  order: 1;
}
</style>
